package com.ruoyi.service;

import com.ruoyi.dto.ResponseDTO;
import com.ruoyi.mapper.GoodMapper;
import com.ruoyi.pojo.Goods;
import com.ruoyi.pojo.Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodServiceImpl implements GoodService{
    @Autowired
    private GoodMapper goodMapper;
    @Override
    public ResponseDTO getAllType() {
        List<Type> types=goodMapper.getAllType();
        return ResponseDTO.success(types);
    }

    @Override
    public ResponseDTO getGoodsByType(String id,String storeId) {
        List<Goods> goods=goodMapper.getGoodsByType(id,storeId);
        return ResponseDTO.success(goods);
    }

    @Override
    public ResponseDTO addGood(String storeId,String name, String price, String remark, String typeId, String image) {
        int res=goodMapper.addGodd(name,price,remark,typeId,image,storeId);
        System.out.println(storeId);
        if(res>0){
            return ResponseDTO.success("添加成功");
        }
        else{
            return ResponseDTO.error("添加失败");
        }
    }

    @Override
    public ResponseDTO editGood(String storeId,String id,String name, String price, String remark, String typeId, String image) {
        int res=goodMapper.editGood(storeId,id,name,price,remark,typeId,image);
        if(res>0){
            return ResponseDTO.success("修改成功");
        }
        else{
            return ResponseDTO.error("修改失败");
        }
    }

    @Override
    public ResponseDTO deleteGood(String storeId,String id) {
        int res=goodMapper.deleteGood(storeId,id);
        if(res>0){
            return ResponseDTO.success("删除成功");
        }
        else{
            return ResponseDTO.error("删除失败");
        }
    }

    @Override
    public ResponseDTO addClass(String name, String image) {
        int res=goodMapper.addClass(name,image);
        if(res>0){
            return ResponseDTO.success("添加成功");
        }
        else{
            return ResponseDTO.error("添加失败");
        }
    }

    @Override
    public ResponseDTO editClass(String id, String name, String image) {
        int res=goodMapper.editClass(id,name,image);
        if(res>0){
            return ResponseDTO.success("修改成功");
        }
        else{
            return ResponseDTO.error("修改失败");
        }
    }

    @Override
    public ResponseDTO deleteClass(String id) {
        int res=goodMapper.deleteClass(id);
        if(res>0){
            return ResponseDTO.success("删除成功");
        }
        else{
            return ResponseDTO.error("删除失败");
        }
    }

    @Override
    public ResponseDTO searchGood(String storeId,String name) {
        List<Goods> goods=goodMapper.searchGood(storeId,name);
        return ResponseDTO.success(goods);
    }

}

